package cn.com.blueInfo.bpm.system.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.system.request.ApplicationDTO;
import cn.com.blueInfo.bpm.system.response.ApplicationVO;
import cn.com.blueInfo.bpm.system.service.ApplicationService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 租户系统表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:37:55
 */
@Tag(name = "租户系统 接口")
@RestController
@RequestMapping("/system/application")
public class ApplicationController extends BaseController {

    @Autowired
    private ApplicationService applicationService;

    /**
     * 新建租户系统
     * @param applicationDTO 租户系统参数
     * @return ResultInfo
     */
    @Operation(summary = "新增租户系统")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createApplication(
            @Validated({Create.class, Default.class}) @RequestBody ApplicationDTO applicationDTO) {
        return applicationService.addApplication(applicationDTO);
    }

    /**
     * 批量新建租户系统
     * @param applicationDTOList 租户系统参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建租户系统")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateApplication(
            @Validated({Create.class, Default.class}) @RequestBody List<ApplicationDTO> applicationDTOList) {
        return applicationService.batchAddApplication(applicationDTOList);
    }

    /**
     * 根据ID删除租户系统
     * @param applicationId 租户系统ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除租户系统")
    @DeleteMapping("/removeInfo/{applicationId}")
    public ResultInfo<Integer> deleteApplicationById(
            @Parameter(name = "ID") @PathVariable Long applicationId) {
        return applicationService.removeApplication(applicationId);
    }

    /**
     * 批量根据ID删除租户系统
     * @param applicationIdList 租户系统ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除租户系统")
    @DeleteMapping("/removeInfoList/{applicationIdList}")
    public ResultInfo<Integer> batchDeleteApplicationById(
            @Parameter(name = "ID") @PathVariable List<Long> applicationIdList) {
        return applicationService.batchRemoveApplication(applicationIdList);
    }

    /**
     * 根据ID全量更新租户系统
     * @param applicationId 租户系统ID
     * @param applicationDTO 租户系统参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新租户系统")
    @PutMapping("/modifyInfo/{applicationId}")
    public ResultInfo<Integer> updateApplicationFull(
            @Parameter(name = "ID") @PathVariable Long applicationId,
            @Validated({Update.class, Default.class}) @RequestBody ApplicationDTO applicationDTO) {
        validateUpdateId(applicationId, applicationDTO.getId());
        return applicationService.modifyApplication(applicationDTO);
    }

    /**
     * 根据ID部分更新租户系统
     * @param applicationId 租户系统ID
     * @param applicationUpdatePartialDTO 租户系统参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新租户系统")
    @PatchMapping("/modifyPartialInfo/{applicationId}")
    public ResultInfo<Integer> updateApplicationPartial(
            @Parameter(name = "ID") @PathVariable Long applicationId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            ApplicationDTO.UpdatePartialDTO applicationUpdatePartialDTO) {
        validateUpdateId(applicationId, applicationUpdatePartialDTO.getId());
        return applicationService.modifyApplicationPartial(applicationUpdatePartialDTO);
    }

    /**
     * 根据ID查询租户系统
     * @param applicationId 租户系统ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询租户系统")
    @GetMapping("/getInfo/{applicationId}")
    public ResultInfo<ApplicationVO> getApplicationById(
            @Parameter(name = "ID") @PathVariable Long applicationId) {
        return applicationService.queryApplicationById(applicationId);
    }

    /**
     * 分页查询租户系统
     * @param applicationQueryDTO 租户系统参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询租户系统")
    @GetMapping("/getInfos")
    public ResultInfo<Page<ApplicationVO>> getApplicationPage(
            @Validated ApplicationDTO.QueryDTO applicationQueryDTO) {
        return applicationService.queryApplicationPage(applicationQueryDTO);
    }

    /**
     * 根据条件查询租户系统
     * @param applicationQueryDTO 租户系统参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询租户系统")
    @GetMapping("/getInfoList")
    public ResultInfo<List<ApplicationVO>> getApplicationList(
            @Validated ApplicationDTO.QueryDTO applicationQueryDTO) {
        return applicationService.queryApplicationList(applicationQueryDTO);
    }

}
